<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var person = (function () {
            //声明一个对象，增删改查均是针对这个对象
            var personInfo = {
                name: "李四",
                age: 20
            };
            //返回一个对象，这个对象中封装了一些对personInfor操作的方法
            return {
                //根据给定的属性获取这个属性的值
                getInfo: function (property) {
                    return personInfo[property];
                },
                //修改一个属性值
                modifyInfo: function (property, newValue) {
                    personInfo[property] = newValue;

                },
                //添加新的属性
                addInfo: function (property, value) {
                    personInfo[property] = value;

                },
                //删除指定的属性
                delInfo: function (property) {
                    delete personInfo[property];
                }
            }
        })();

        alert(person.getInfo("name"));
        person.addInfo("sex", "男");
        alert(person.getInfo("sex"));


        person.delInfo("name");
        alert(person.getInfo("name"));
    </script>
</body>

</html>